package com.example.seller_svc.service;

import java.time.LocalDateTime;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.example.seller_svc.model.EntrustOrder;
import com.example.seller_svc.repository.EntrustRepository;

@Service
public class EntrustService {

    @Autowired
    private EntrustRepository entrustRepository;

    public EntrustOrder submitEntrust(EntrustOrder order) {
        (order).setStatus("待处理");
        order.setCreateTime(LocalDateTime.now());
        return (EntrustOrder) entrustRepository.save(order);
    }

    public List<EntrustOrder> getAll() {
        return entrustRepository.findAll();
    }

    public EntrustOrder updateStatus(Long id, String status) {
        EntrustOrder order = (EntrustOrder) entrustRepository.findById(id).orElseThrow();
        (order).setStatus(status);
        return (EntrustOrder) entrustRepository.save(order);
    }

    public void deleteOrder(Long id) {
        entrustRepository.deleteById(id);
    }
}